

export default function request(options) {
    let header = options.header || {};
    let data = options.data || {};
    const baseURL = 'http://192.168.2.49:18080'
    let token = uni.getStorageSync('token');
    header['token'] = token ? token : "";
    header['Authorization'] = 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
    header['blade-auth'] = 'bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJyb2xlX25hbWUiOiJhZG1pbmlzdHJhdG9yIiwidXNlcl9pZCI6IjExMjM1OTg4MjE3Mzg2NzUyMDEiLCJyb2xlX2lkIjoiMTEyMzU5ODgxNjczODY3NTIwMSIsInVzZXJfbmFtZSI6ImFkbWluIiwidG9rZW5fdHlwZSI6ImFjY2Vzc190b2tlbiIsImRlcHRfaWQiOiIxNjM4NDUxODgxNDI5NzIxMDg5IiwiYWNjb3VudCI6ImFkbWluIiwiY2xpZW50X2lkIjoic2FiZXIiLCJleHAiOjE2ODM1MjYzNzgsIm5iZiI6MTY4MTg4NjExNn0.UpmN954t2rXuPKeeMzj6omlU8s1YhU1MCA4gJReYPTM--J8EdlVf7mT2reL8smSf0h4pTYKR3zfzhaVN9pYBKA'
    // //全局参数
    // let memberId = uni.getStorageSync('memberId');
    // data.memberId = memberId ? memberId : "";

    // let eaId = uni.getStorageSync('eaId');
    // data.eaId = eaId ? eaId : "";

    // if (options.url != '/auth/login' && !token) {
    //     uni.reLaunch({
    //         url: '/pages/login/login.vue'
    //     });
    //     return
    // }

    //  发起请求 加载动画
    if (!options.hideLoading) {
        uni.showLoading({
            title: "加载中"
        })
    }

    //  发起网络请求
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseURL + options.url,
            method: options.method,
            header: header,
            data: data,
            // dataType: "json",
            // sslVerify: false, // 是否验证ssl证书
            success: res => {
                if (res.statusCode && res.statusCode != 200) {
                    return uni.showModal({
                        content: res.errMsg ? res.errMsg : '出错了'
                    })
                }
                resolve(res.data)
            },
            fail: err => {
                uni.showModal({
                    content: err.errMsg ? err.errMsg : "出错了"
                })
                reject(err)
            },
            complete: (e) => {
                console.log("请求完成");
                uni.hideLoading()
            }
        })
    })

}